//
//	 ______    ______    ______    
//	/\  __ \  /\  ___\  /\  ___\   
//	\ \  __<  \ \  __\_ \ \  __\_ 
//	 \ \_____\ \ \_____\ \ \_____\ 
//	  \/_____/  \/_____/  \/_____/ 
//
//	Powered by BeeFramework
//
//
//  Board_iPhone_Settings.m
//  DingDing
//
//  Created by LHL on 14/11/26.
//  Copyright (c) 2014年 com.gordon. All rights reserved.
//

#import "Board_iPhone_Settings.h"
#import "EditPetsDocument.h"
#import "Board_iPhone_UpdatePassWord.h"
//#import <ShareSDK/ShareSDK.h>
#import <SDWebImage/UIImageView+WebCache.h>
#import "Common.h"
#import "AppBoard_iPhone.h"
#pragma mark -
@interface Board_iPhone_Settings()<UIAlertViewDelegate>
{
	//<#@private var#>
}
@end

@implementation Board_iPhone_Settings

SUPPORT_AUTOMATIC_LAYOUT( YES )
SUPPORT_RESOURCE_LOADING( YES )
DEF_OUTLET(BeeUIImageView, head_img)
DEF_OUTLET(BeeUILabel, isboundle)
DEF_OUTLET(BeeUIButton, dataupdate)
- (void)load
{
}

- (void)unload
{
}

#pragma mark - Signal

ON_CREATE_VIEWS( signal )
{
    self.navigationBarShown = YES;
    self.view.backgroundColor = RGB(246, 246, 246);
    self.title = @"设置";
    if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"logintype"] isEqualToString:@"weibo"]) {
        self.isboundle.text = @"已绑定";
    }else{
        self.isboundle.text = @"未绑定";
    }
    NSData *data = [[NSUserDefaults standardUserDefaults]objectForKey:@"head_img"];
    self.head_img.image = [self imageWithImageSimple:[UIImage imageWithData:data] scaledToSize:CGSizeMake(33, 33)];
    
    self.navigationBarLeft = [UIImage imageNamed:@"back.png"];
}
- (UIImage *)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize{
    UIGraphicsBeginImageContext(newSize);
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

ON_DELETE_VIEWS( signal )
{
}

ON_LAYOUT_VIEWS( signal )
{
}

ON_WILL_APPEAR( signal )
{
    self.navigationBarShown = YES;
}

ON_DID_APPEAR( signal )
{
}

ON_WILL_DISAPPEAR( signal )
{
}

ON_DID_DISAPPEAR( signal )
{
}

ON_SIGNAL3( BeeUINavigationBar, LEFT_TOUCHED, signal )
{
    [self.navigationController popViewControllerAnimated:YES];
}

ON_SIGNAL3( BeeUINavigationBar, RIGHT_TOUCHED, signal )
{
}

ON_SIGNAL3(BeeUIButton, dataupdate, SIGNAL){
    EditPetsDocument *dit = [[EditPetsDocument alloc]init];
    [self.navigationController pushViewController:dit animated:YES];
}
ON_SIGNAL3(BeeUIButton, pwdUpdate, SIGNAL){
    Board_iPhone_UpdatePassWord *pwd = [[Board_iPhone_UpdatePassWord alloc]init];
    [self.navigationController pushViewController:pwd animated:YES];
}

ON_SIGNAL3(BeeUIButton, logout, SIGNAL){
    UIAlertView *alter = [[UIAlertView alloc]initWithTitle:@"提示" message:@"确定要退出吗" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [alter show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 1) {
        NSUserDefaults *users = [NSUserDefaults standardUserDefaults];
        [users setObject:@"1" forKey:@"logout"];
        [users synchronize];
        [Common cleanUserInfo];
        [[EaseMob sharedInstance].chatManager asyncLogoff];
        [self.navigationController popToRootViewControllerAnimated:YES];
        [[NSNotificationCenter defaultCenter]postNotificationName:@"logout" object:nil];

    }
}

@end
